<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RetailOrder extends Model
{
    use HasFactory;
    public function scopeSearch($query, $params)
    {

        if(!empty($params['manufacturer_id'])){
            $query->where('manufacturer_id', $params['manufacturer_id']);
        }

        if(!empty($params['goods_id'])){
            $query->where('goods_id', $params['goods_id']);
        }

        if(!empty($params['customer_id'])){
            $query->where('customer_id', $params['customer_id']);
        }

        if(!empty($params['start_time']) && !empty($params['end_time'])){
            $query->whereBetween('order_time', [$params['start_time'],$params['end_time']]);
        }
        return $query;


    }

    public function manufacturer(){
        return $this->belongsTo(Manufacturer::class);
    }
    public function goods(){
        return $this->belongsTo(Goods::class);
    }
    public function customer(){
        return $this->belongsTo(Customer::class);
    }
}
